# -*- coding: utf-8 -*-

import logging

from flask import Blueprint, request

from flask_restful import Api

from utils.auth import current_user

logger = logging.getLogger(__name__)

ins = Blueprint(
    'ins',
    __name__
)

ins_api = Api(ins)

from . import views


@ins.before_request
def validate_user():
    logger.debug('Request for endpoint: %s', request.endpoint)
    if request.endpoint == 'ins.login':
        logger.debug('User is trying to log in ...')
        return
    user = current_user._get_current_object()
    logger.debug('User %s is visiting: %s', user.openid, request.endpoint)
